<?php

get_template_part('secondary', 'header');
get_template_part('secondary', 'sidebar');

global $wp_query, $query_string;

$termname = $wp_query->queried_object->name;
$termslug = $wp_query->queried_object->slug;

$selected = ' selected="selected" ';
$main_link = Helpers::get_consumption_type_url($termslug);
$cp_link = Helpers::get_consumption_type_filtered_url($termslug, 'corto-plazo');
$mp_link = Helpers::get_consumption_type_filtered_url($termslug, 'mediano-plazo');
$lp_link = Helpers::get_consumption_type_filtered_url($termslug, 'largo-plazo');

$query_string = $query_string . '&orderby=title&order=ASC';
query_posts($query_string);

$paged = $wp_query->query_vars['paged'];
if ($paged == 0) {
    $paged = 1;
}

?>

<script type="text/javascript"><!--
    jQuery(document).ready(function($){
 
        $('#dropdown').change(function(e) {
            window.location.href = $("#dropdown option:selected").attr("data-link");
        });
  
    });
</script>

<div id="dash-content">
    <header class="header-buenas-practicas">
        <h2>BUENAS PR&Aacute;CTICAS AMBIENTALES</h2>
    </header> 
    <div class="blog-contetn">
        <?php if (have_posts()) : ?>
            <ul id="blog">
                <li>
                    <h3><?php echo $termname; ?></h3>
                    <h4>Se encontraron <?php echo $wp_query->found_posts; ?> buenas pr&aacute;cticas</h4>
                </li>
                <?php while (have_posts()) : the_post(); ?>
                    <li>
                        <a href="<?php the_permalink(); ?>">
                            <figure>
                                <?php the_post_thumbnail(array(248, 145)); ?>
                            </figure>
                            <h3><?php the_title(); ?></h3>
                            <p><?php the_excerpt(); ?></p>
                        </a>
                    </li>
                <?php endwhile; ?>
            </ul>
        <?php endif; ?>
        <div id="pagination">
            <div class="pag-prev">
                <?php previous_posts_link('Anterior'); ?>
            </div>
            <div class="pags">
                <ul class="paginas">
                    <?php for ($i = 1; $i <= $wp_query->max_num_pages; $i++) { ?>
                            <li>
                                <a href="<?php echo Helpers::get_consumo_paginated_url($termslug, $i); ?>" <?php
                                    if ($i == $paged) {
                                        echo 'class="bolded"';
                                    }
                                    ?> ><?php echo $i; ?></a>
                            </li>
                    <?php } ?>
                </ul>
            </div>
            <div class="pag-next">
                <?php next_posts_link('Siguiente'); ?>
            </div>
        </div>
    </div>

</div>
